/**
 * @FileName: MarketingController.java
 * @Author
 * @Description:
 * @Date 2016年4月15日 上午10:40:45
 * @CopyRight ZTE Corporation
 */
package cn.hpclub.server.controller.h5;

import java.util.HashMap;

import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.kit.StrKit;

import cn.hpclub.server.constant.Constant;
import cn.hpclub.server.constant.H5ApiConstant;
import cn.hpclub.server.util.HttpUtil;
import cn.hpclub.server.util.SystemConfigUtil;

/**
 * 营销顾问
 */
public class MarketingController extends BaseH5Controller{
    private static final Logger logger           = LoggerFactory.getLogger(MarketingController.class);
    private String              CMCC_HOST_PREFIX = SystemConfigUtil.getSystemConfig().getCmccHostPrefix();

    /**
     * 搜索推荐业务
     * 
     * @Title: search
     * @Description:TODO void
     */
    public void search(){
        JSONObject returnObj = setResponseObj(H5ApiConstant.ResultCode.FAIL_CODE,
                                              H5ApiConstant.Msg.REC_BUSINESS_EXCEPTION, null);
        String result = getQryRecommendBusinessResult();
        // logger.warn("request contactRecommend result = " + result);
        // result =
        // "{\"resCode\":\"0000000\",\"outData\":{\"PHONE_NO\":\"13402800392\",\"STATUS\":\"T\",\"ACTIVE_LIST\":[{\"ACTIVENAME\":\"4G资费合约（38包打58三星级以上）cd\",\"ACTIVECODE\":\"2016041519240180\",\"ACTIVETYPE_LEVEL_SUPER\":\"1006\",\"ACTIVETYPE_LEVEL_PARENT\":\"1006\",\"ACTIVETYPE_NAME\":\"1006\",\"DEPARTMENT\":\"100\",\"REGIONCODE\":\",0816,0838,028\",\"REGIONNAME\":\",绵阳,德阳,成都\",\"PRIORITY\":\"1\",\"BEGINTIME\":\"2016-04-15\",\"ENDTIME\":\"2016-05-31\",\"DESCRIPTION\":\"欢迎参加四川移动4G优惠活动，使用约定资费并在网6个月，保底58元，即可享受：1、话费赠送：每月划拨20元，从参与活动次月起划拨6个月，可抵扣小额支付外的所有费用，使用有效期3个月；2、积分赠送：从参与活动次月起连续6个月每月赠送116分，积分有效期一年。\",\"PRCTUREPATH\":\"\",\"BUSINESSTYPE_LEVEL_1\":\"MAINMODE\",\"BUSINESSTYPE_LEVEL_2\":\"主套餐\",\"BUSINESSTYPE_LEVEL_3\":\"ACAZ25128\",\"BUSINESNAME\":\"4G飞享套餐58版\",\"OPCODE\":\"1104\",\"URL\":\"\",\"PICTITLE\":\"\",\"MARKETINGTERM\":\"欢迎参加四川移动4G优惠活动，使用约定资费并在网6个月，保底58元，即可享受：1、话费赠送：每月划拨20元，从参与活动次月起划拨6个月，可抵扣小额支付外的所有费用，使用有效期3个月；2、积分赠送：从参与活动次月起连续6个月每月赠送116分，积分有效期一年。\"}],\"BASIS_LABEL\":{\"PHONE\":\"13402800392\",\"PROD_PRIC_ID\":\"ACAZ22713\",\"ARPU_3MONTH_AVG\":\"44.55\",\"FLOW_3MONTH_AVG\":\"184.89\",\"DUR_3MONTH_AVG\":\"322.50\",\"G4_USER_FLAG\":\"0\",\"G4_TERMUSER\":\"0\",\"IMEI_CHG_AVG_FLAG\":\"1\",\"DATA_WAP_17_COLUMN\":\"1\",\"G4_USER_PRC\":\"0\",\"TERM_BRAND\":\"000270\",\"TERM_MODEL\":\"Iphone
        // 5
        // \",\"IMEI_CHG_TIMES\":\"5\",\"IMEI_CHG_LAST_TIME\":\"2015-10-03\",\"TERM_ACTIVE\":\"1\",\"TERM_EFF_TIME\":\"20150616\",\"TERM_EXP_TIME\":\"20150702\",\"WAP_USE_PERCENT\":\"0.9145\",\"WAP_PRE_USE_AMOUNT\":\"313901\",\"WAP_CUR_USE_AMOUNT\":\"0\",\"WAP4G_PRE_USE_AMOUNT\":\"0\",\"WAPXS_PRE_USE_AMOUNT\":\"84143\"},\"MARKET_LABEL\":{\"TERM_MODEL\":\"Iphone
        // 5 \",\"G4_TERMUSER\":\"0 \",\"CREDIT_CLASS\":\"3
        // \",\"USER_ID\":\"11104022605371\",\"KD_FLAG\":\"1\",\"PROD_PRIC_NAME\":\"畅聊38套餐\"}},\"resMsg\":\"OK\"}";
        // if(StrKit.notBlank(result)){
        // renderText(result);
        // }

        try{
            if(StrKit.notBlank(result)){
                renderText(result);
                return;
            }
        }
        catch(Exception e){
            e.printStackTrace();
        }

        renderJson(returnObj.toString());
    }

    /**
     * @Title: getResult
     * @Description:TODO
     * @return String
     */

    private String getQryRecommendBusinessResult(){
        String result = "";
        try{
            String phoneNo = getPara(H5ApiConstant.Ui.PHONENO);
            // String encodeParams = encodeParams(getCustRealChkParams());
            // logger.debug("encodeParams = " + encodeParams);
            HashMap<String, Object> hm = new HashMap<String, Object>();
            // JSONObject o = new JSONObject(encodeParams);
            // hm.put(H5ApiConstant.CmccKey.RAWSTR,
            // o.get(H5ApiConstant.CmccKey.RAWSTR));
            hm.put("phone_no", phoneNo);
            result = HttpUtil.getHttpByPost(CMCC_HOST_PREFIX + Constant.Url.QUERY_RECOMMEND_BUSINESS, hm);
        }
        catch(Exception e){
            e.printStackTrace();
        }

        return result;
    }
}
